package com.timo.rabbitmq.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Description: Rabbit MQ连接测试
 * @Author: Timo
 * @Date: 2019/7/22 10:20
 */
public class RabbitMqConnectionTest {

    public static void main(String[] args) {

    }


    public enum MqQueue{
        TIMO_HELLO_QUEUE("timo_hello_queue"),
        TIMO_GOODMORNING_QUEUE("timo_goodmorning_queue");

        private String queueName;

        MqQueue(String queueName) {
            this.queueName = queueName;
        }
    }


    /**
     * host: 192.168.146.129
     *     port: 5672
     *     username: admin
     *     password: 123456
     * @return
     */
    public ConnectionFactory connectionFactory() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.146.129");
        factory.setPort(5672);
        factory.setUsername("admin");
        factory.setPassword("123456");

        return factory;
    }


    public Connection connection() throws IOException, TimeoutException {
        return connectionFactory().newConnection();
    }

    public Channel channel() throws IOException, TimeoutException {
        return connection().createChannel();
    }

}
